package cn.hui.utils;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;

@SuppressWarnings("rawtypes")
public class Data implements Serializable {
	private static final long serialVersionUID = 6233023949275222296L;

	@SuppressWarnings("unchecked")
	public static final HashMap<String, Class> typeMapping = new HashMap(){
		private static final long serialVersionUID = 4512649930334841329L;

	{
		put("tinyint", Short.class);
		put("int", Integer.class);
		put("smallint", Integer.class);
		put("integer", Integer.class);
		put("bigint", Long.class);
		put("varchar", String.class);
		put("date", Timestamp.class);
		put("timestamp", Timestamp.class);
		put("datetime", Timestamp.class);
		put("tinytext", String.class);
		put("text", String.class);
		put("longtext", String.class);
		put("enum", String.class);
		put("decimal", Double.class);
		put("double", Double.class);
		put("char", String.class);
	}};

	public static Class getType(String type) {
		type = type.split(" ")[0];
		int index = type.indexOf('(');
		if (index != -1) {
			type = type.substring(0, index);
		}
		Class clazz = (Class) typeMapping.get(type);
		return clazz != null ? clazz : String.class;
	}

}
